package com.zhkj.txg.module.mine.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.txg.R
import com.zhkj.txg.module.mine.entity.CouponEntity
import java.math.BigDecimal

class CouponCenterAdapter :
    BaseQuickAdapter<CouponEntity, BaseViewHolder>(R.layout.item_coupon), LoadMoreModule {

    init {
        addChildClickViewIds(R.id.tvCouponGet, R.id.viewCoupon)
    }

    override fun convert(helper: BaseViewHolder, item: CouponEntity) {
        helper.setText(R.id.tvCouponPrice, item.money.toString())
            .setText(R.id.tvCouponName, item.name)
            .setText(R.id.tvCouponValidity, "${item.startTime}到${item.endTime}")
            .setGone(R.id.tvCouponGet, item.isGet)
            .setText(
                R.id.tvCouponLimit,
                if (item.condition >= 0) context.getString(
                    R.string.condition_format,
                    BigDecimal(item.condition)
                ) else context.getString(R.string.condition_non)
            )
    }

    fun refreshItem(uiPosition: Int) {
        data[uiPosition].isGet = true
        notifyItemChanged(uiPosition)
    }
}